home *** CD-ROM | disk | FTP | other *** search
/ Trading on the Edge / Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin / pc / shared / freeman / bam.m < prev    next >
Text File  |  1993-10-27  |  2KB  |  54 lines

  1. BeginPackage["Bam`"]
  2.  
  3. makeXtoYwts::usage = "makeXtoYwts[exemplars]"
  4. psi::usage = "psi[inValue,netIn]"
  5. phi::usage = "phi[inVector_List,netInVector_List]"
  6. energyBAM::usage = "energyBAM[xx,w,zz]"
  7. bam::usage = "bam[initialX,initialY,x2yWeights,y2xWeights,printAll:False]"
  8.  
  9. Begin["`Private`"]    (* begin the private context *)
  10.  
  11.  
  12. makeXtoYwts[exemplars_] :=
  13.    Module[{temp},
  14.     temp = Map[Outer[Times,#[[2]],#[[1]]]&,exemplars];
  15.     Apply[Plus,temp]
  16.     ];  (* end of Module *)
  17.  
  18.  
  19.  
  20.  
  21. psi[inValue_,netIn_] := If[netIn>0,1,If[netIn<0,-1,inValue]];
  22. phi[inVector_List,netInVector_List] :=
  23.     MapThread[psi[#,#2]&,{inVector,netInVector}]; 
  24.  
  25.  
  26. energyBAM[xx_,w_,zz_] := - (xx . w . zz) 
  27.  
  28.  
  29.  
  30. bam[initialX_,initialY_,x2yWeights_,y2xWeights_,printAll_:False] :=
  31.   Module[{done,newX,newY,energy1,energy2},
  32.     done = False;
  33.     newX = initialX;
  34.     newY = initialY;
  35.     While[done == False,
  36.       newY = phi[newY,x2yWeights.newX];
  37.       If[printAll,Print[];Print[];Print["y = ",newY]];
  38.       energy1 = energyBAM[newY,x2yWeights,newX];
  39.       If[printAll,Print["energy = ",energy1]];
  40.       newX =  phi[newX,y2xWeights . newY];
  41.       If[printAll,Print[];Print["x = ",newX]];
  42.       energy2 =  energyBAM[newY,x2yWeights,newX];
  43.       If[printAll,Print["energy = ",energy1]];
  44.       If[energy1 == energy2,done=True,Continue];
  45.     ]; (* end of While *)
  46.     Print[];Print[];
  47.     Print["final y = ",newY,"  energy= ",energy1];
  48.     Print["final x = ",newX,"  energy= ",energy2];
  49.   ];  (* end of Module *)
  50.  
  51.  
  52. End[]         (* end the private context *)
  53.  
  54. EndPackage[]  (* end the package context *)